package com.chennan.workdir.invoiceapplication.domain.repository;

import com.chennan.workdir.invoiceapplication.domain.model.InvoiceApplication;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * @author chennan
 * @createTime 2021年07月26日 18:10:00
 */
public interface InvoiceApplicationMapper {


    String BASIC_FIELD = "id, invoiceApplicationNo, baiwangNo,externalInvoiceApplicationNo, projectId, customerId, " +
            "customerName, invoiceType,invoiceTerminalCode,sellSocialCreditCode, " +
            "socialCreditCode, applicationStatus, partyCServiceFeeRate, createUserId, invoiceTitle,invoiceTitleId, " +
            "applyOrganizationId, invoiceOfferId, invoiceAmount, bank, accountNo, phoneOnInvoice, " +
            "addressOnInvoice, invoiceNumber, invoiceCode, invoiceUrl, invoiceCreateTime, " +
            "expectPaidDate, needPost, postStatus, receiverAddressProvinceId, receiverAddressCityId, " +
            "receiverAddressCountyId, recipientAddressLine, receiverName, receiverPhone, expressCompany," +
            "expressNumber, needReceipt, memoOnInvoice, applicationMemo, memo1, memo2, memo3, memo4," +
            "memo5, invoiceStatus, invoiceCreateStatus, invoiceEmail, createTime, updateTime, " +
            "invalidType, invalidCreateTime, approveMemo, cancelApproveMemo, invalidMemo,relationId," +
            "deleted, customerDepartmentId, customerDepartmentName,useBaiwang," +
            "writeOffAmount,writeOffAmountOnGoing,invoiceInvalidTime,taxSign,billId," +
            "invoiceAmountActual,invoiceNoTaxAmount,invoiceTotalTaxRate,invoiceTaxAmount," +
            "openInvoiceUserId,mergeItem";

    String BASIC_CONDITION ="<if >";

    @Select({
            " SELECT ",
            BASIC_FIELD,
            " FROM F_InvoiceApplication ",
            " WHERE deleted=0 ",
            "limit #{offset},#{pageSize}"
    })
    List<InvoiceApplication> listInvoiceApplicationByPageInfo(@Param("offset") Integer offset,@Param("pageSize") Integer pageSize);

//    @Update({"<script>",
//            "UPDATE F_InvoiceApplication ",
//            " set ",
//            "<trim prefix=\"\" suffix=\"\" suffixOverrides=\",\" >",
//            "   <if test=\"null != dto.currentWriteOffAmount\">",
//            "       writeOffAmountOnGoing = writeOffAmountOnGoing + #{dto.currentWriteOffAmount}, ",
//            "   </if>",
//            "   <if test=\"null != dto.currentAllowanceAmount\">",
//            "       allowanceAmountOnGoing = allowanceAmountOnGoing + #{dto.currentAllowanceAmount}, ",
//            "   </if>",
//            "</trim>",
//            " where id = #{dto.invoiceId} and invoiceCreateStatus = 3 and deleted = 0 and updateTime = #{dto.updateTime}",
//            "</script>"})
//    Integer updateInvoiceWriteOffAmountByDraft(@Param("dto") WriteOffInvoiceItemDto updateInvoiceWriteAmountDto);


}
